﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Congducsan
{
    public partial class FrmRungloi : Form
    {
        public FrmRungloi()
        {
            InitializeComponent();
        }

        private void FrmRungloi_FormClosing(object sender, FormClosingEventArgs e)
        {
            DradApplication.DradApp.FormMain.Show();
        }

        private void FrmRungloi_Resize(object sender, EventArgs e)
        {
            this.Size = new Size(590, 422);
        }

        private void CmdOk_Click(object sender, EventArgs e)
        {
            PrRungloi prRungloi = new PrRungloi();
            prRungloi.Show();
            this.Hide();
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdThietlap_Click(object sender, EventArgs e)
        {
            FrmTuychon frmTuychon = new FrmTuychon();
            frmTuychon.Show();
        }

        private void FrmRungloi_Load(object sender, EventArgs e)
        {
            loadSettingReg();
        }
        //Lưu setting vào registry
        private void saveSettingReg()
        {
            RegistryKey regKey = Registry.CurrentUser;
            regKey = regKey.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            string Values = "";
            string[] Var = regKey.GetValue("KtThan").ToString().Split('\t');
            Values = txtDaymongMin .Text;//0
            Values = Values +"\t"+ Var[1];//1
            Values = Values +"\t"+ txtLopdem .Text;//2
            Values = Values +"\t"+ txtCachkhoangday .Text;//3
            Values = Values +"\t"+ txtSoday .Text;//4
            Values = Values +"\t"+ txtLoaicong .Text;//5
            Values = Values +"\t"+ Var[6];//6
            Values = Values +"\t"+ txtDayong .Text;//7
            Values = Values +"\t"+ txtKhaudien .Text;//8
            Values = Values +"\t"+ txtCaocong .Text;//9
            Values = Values +"\t"+ txtDayban .Text;//10
            Values = Values +"\t"+ Var[11];//11
            Values = Values +"\t"+ Var[12];//12
            Values = Values +"\t"+ txtMomong .Text;//13
            Values = Values +"\t"+ Var[14];//14
            Values = Values +"\t"+ txtLopdemm .Text;//15
            regKey.SetValue("KtThan", Values);
            regKey.SetValue("GlobalLytrinh", txtLytrinh.Text);
            regKey.Close();
        }
        private void loadSettingReg()
        {
            RegistryKey regKey = Registry.CurrentUser;
            RegistryKey testKey = regKey.OpenSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            if (testKey != null)
            {
                regKey = regKey.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
                string str = regKey.GetValue("KtThan").ToString();
                string[] STR = str.Split('\t');
                int i = 0;
                txtDaymongMin .Text=STR[i++]; //0
                 //     Var(1) .Text;//1
                i++;
                txtLopdem.Text = STR[i++];//2
                txtCachkhoangday.Text = STR[i++];//3
                txtSoday.Text = STR[i++];//4
                txtLoaicong.Text = STR[i++];//5
                //     Var(6) .Text;//6
                i++;
                txtDayong.Text = STR[i++];//7
                txtKhaudien.Text = STR[i++];//8
                txtCaocong.Text = STR[i++];//9
                txtDayban.Text = STR[i++];//10
                //     Var(11) .Text;//11
                i++;
                //     Var(12) .Text;//12
                i++;
                txtMomong.Text = STR[i++];//13
                //     Var(14) .Text;//14
                i++;
                txtLopdemm.Text = STR[i++];//15
                regKey.Close();
            }
        }

        private void FrmRungloi_FormClosed(object sender, FormClosedEventArgs e)
        {
            saveSettingReg();
        }
    }
}
